package com.bruce.demo2.patterns.demo1.creational.demo05.builder.demo3;

/**
 * @PROJECT_NAME design_patterns
 * @DESCRIPTION 手机-建造者模式构造实例化对象
 * @AUTHOR CNBruceLee
 * @DATE 2021/7/13 21:00
 */
public class Phone {
    private String cpu;
    private String screen;
    private String memory;
    private String mainbord;

    private Phone(Builder builder) {
        this.cpu = builder.cpu;
        this.screen = builder.screen;
        this.memory = builder.memory;
        this.mainbord = builder.mainbord;
    }

    public static final class Builder {
        private String cpu;
        private String screen;
        private String memory;
        private String mainbord;

        public Builder cpu(String cpu) {
            this.cpu = cpu;
            return this;
        }

        public Builder screen(String screen) {
            this.screen = screen;
            return this;
        }

        public Builder memory(String memory) {
            this.memory = memory;
            return this;
        }

        public Builder mainbord(String mainbord) {
            this.mainbord = mainbord;
            return this;
        }

        /**
         * 使用构建者创建手机对象
         * @return 创建Phone
         */
        public Phone builder() {
            return new Phone(this);
        }
    }

    @Override
    public String toString() {
        return "Phone{" +
                "cpu='" + cpu + '\'' +
                ", screen='" + screen + '\'' +
                ", memory='" + memory + '\'' +
                ", mainbord='" + mainbord + '\'' +
                '}';
    }
}
